<?php

namespace App\Jobs;

use App\Modules\Jobs\Services\UpdateUserAverageService;
use App\Modules\Jobs\Services\UpdateUserDetailService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\Log;

class CreateTask implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    protected $data;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct($data)
    {
        //
        //Log::debug(var_export($data,true));
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        /*Log::info('opopopop:'.var_export($this->data,true));
        //file_put_contents('index.txt','hhhhhhhhhhhhhhhhhhhhhhhhhhhhh');
        die;*/
        $data =$this->data;
        if($data){
            try{
                UpdateUserDetailService::UserTaskNum($data->uid);
                UpdateUserAverageService::getUserTaskNum();
            }catch (\Exception $e){
                Log::debug($e->getCode().$e->getMessage());
            }
        }else{
            Log::error('CreateTask:No data !');
        }
        Log::info("CreateTask:executed!".json_encode($data,JSON_UNESCAPED_UNICODE));
    }
}
